package com.zoffy.zoffyapi.controller;


import com.zoffy.zoffyapi.commen.BaseResponse;
import com.zoffy.zoffyapi.commen.ResultUtils;

import com.zoffy.zoffyapi.model.dto.user.UserInfoUpdateRequest;
import com.zoffy.zoffyapi.model.dto.user.UserLoginRequest;
import com.zoffy.zoffyapi.model.dto.user.UserRegisterRequest;
import com.zoffy.zoffyapi.model.vo.AkSkRequest;
import com.zoffy.zoffyapi.model.vo.AkSkVo;
import com.zoffy.zoffyapi.model.vo.UserVo;
import com.zoffy.zoffyapi.service.UserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/user")
@RestController
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("/register")
    public BaseResponse userRegister(@RequestBody UserRegisterRequest userRegisterRequest){
        String userAccount=userRegisterRequest.getUserAccount();
        String userPassword=userRegisterRequest.getUserPassword();
        String checkPassword=userRegisterRequest.getCheckPassword();
        long userId= userService.userRegister(userAccount,userPassword,checkPassword);
        return ResultUtils.success(userId);
    }
    @PostMapping("/login")
    public BaseResponse<UserVo> userLogin(HttpServletRequest request, @RequestBody UserLoginRequest userLoginRequest){
        String userAccount=userLoginRequest.getUserAccount();
        String userPassword=userLoginRequest.getUserPassword();
        UserVo userVo = userService.userLogin(request,userAccount,userPassword);
        return ResultUtils.success(userVo);
    }

    @GetMapping("/current")
    public BaseResponse<UserVo> getCurrentUser(HttpServletRequest request){
        UserVo userVo=userService.getCurrentUserVo(request);
        return ResultUtils.success(userVo);
    }
    @PostMapping("/update")
    public BaseResponse updateUserInfo(HttpServletRequest request, @RequestBody UserInfoUpdateRequest userInfoUpdateRequest){
        UserVo flag = userService.updateUserInfo(request, userInfoUpdateRequest);
        return ResultUtils.success(flag);
    }
    @PostMapping("/akSk/get")
    public BaseResponse<AkSkVo> getAkSk(HttpServletRequest request,@RequestBody AkSkRequest akSkRequest){
        AkSkVo akSk = userService.getAkSk(request, akSkRequest);
        return ResultUtils.success(akSk);
    }
    @PostMapping("/akSk/update")
    public BaseResponse<AkSkVo> updateAkSk(HttpServletRequest request,@RequestBody AkSkRequest akSkRequest){
        AkSkVo akSk = userService.updateAkSk(request, akSkRequest);
        return ResultUtils.success(akSk);
    }
}
